package cn.project.engineering.ui.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import cn.project.engineering.R;
import cn.project.engineering.http.bean.DianjiaTwonfo;

class DianjianTwoJava extends BaseQuickAdapter<DianjiaTwonfo, BaseViewHolder> {
    public DianjianTwoJava(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, DianjiaTwonfo item) {


        holder.setText(R.id.left_bottom_number,item.getItemNO());
        holder.setText(R.id.left_bottom_xm,item.getItemName());
        holder.setText(R.id.left_bottom_nr,item.getItemContent());

        holder.setText(R.id.left_bottom_jguo,item.getResult());
        holder.setText(R.id.left_bottom_lx,item.getItemType());

        switch(item.getItemType()){
            case "数值" :{
                holder.setVisible(R.id.left_bottom_nr,true);
                holder.setGone(R.id.left_bottom_nr_text,true);
                holder.setGone(R.id.sp1,true);

                ((EditText)holder.getView(R.id.left_bottom_nr)).addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence p0, int i, int i1, int i2) {
                        item.setItemContent(p0.toString()+"");


                        if (p0.toString().equals("")){
                            return ;
                        }
                        int valeu=Integer.valueOf(p0.toString());
                        if ((Integer.valueOf(item.getUpValue())<valeu)&&(valeu<Integer.valueOf(item.getDownValue()))){
                            item.setResult("正常");
                        }else {
                            item.setResult("不正常");
                        }

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {

                    }
                });


            }
            case  "选项" : {
                holder.setVisible(R.id.sp1,true);
                holder.setGone(R.id.left_bottom_nr_text,true);
                holder.setGone(R.id.left_bottom_nr,true);

              Spinner spinner= holder.getView(R.id.sp1);
              spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

                  }

                  @Override
                  public void onNothingSelected(AdapterView<?> adapterView) {

                  }
              });
                spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        spinner.setSelection(i);
                    }
                });

            }
            case "文本": {
                holder.setVisible(R.id.left_bottom_nr_text, true);
                holder.setGone(R.id.left_bottom_nr, true);
                holder.setGone(R.id.sp1, true);
                ((EditText)holder.getView(R.id.left_bottom_nr_text)).addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence p0, int i, int i1, int i2) {
                        item.setItemContent(p0.toString()+"");
                        item.setResult(p0.toString()+"");


                    }

                    @Override
                    public void afterTextChanged(Editable editable) {

                    }
                });

            }

        }
    }
}
